#pragma once
#include "pointBase.h"
#include "connprovider.h"
#include "tlv12.h"
#include "media_procotol.h"
#include "json/json.h"

class CMediaPoint 
: public CPointBase 
, public IConnectionSink
{
public:
	CMediaPoint(CPointSink* pSink, DWORD inType);
	virtual ~CMediaPoint();
	
	TransportAddress GetPeerAddr();
	RtResult SetConnection(void *pConnection);

	virtual void DisconnectSelf();

public:
	void SendJson(uint16_t ucmd, int16_t iresult, const string& strJson);
	void SendMedia(uint16_t ucmd, int16_t iresult, uint32_t pts, uint8_t* pData, uint16_t nLen);

protected:
	// from IConnectionSink	
	virtual void OnReceiveData(CRtMessageBlock& aData, IConnection* pConn);
	virtual void OnDisconnect(RtResult aReason, IConnection* pConn);
	virtual void OnSend(IConnection* pConn);
	
protected:
	void	OnMediaRoomReq(char* szJson);

protected:
	virtual RtResult SendData(CRtMessageBlock &aData);
	
private:
	void OnReceiveTlv(LPBYTE pdata, INT ilen);
	
private:
	CRtAutoPtr<IConnection>	m_pConnect;
	CRtString				m_strMsgBuf;

	TransportAddress		m_peerAddr;
};


